package cn.worldyao.homework.controller;

import cn.worldyao.homework.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class Index {

    public static String TEA_PATH = "tea/";
    public static String STU_PATH = "stu/";

    @RequestMapping("/index")
    public String test1(Model model) {

        model.addAttribute("haha", "我的天");
        return STU_PATH + "stu-login";
    }

    @RequestMapping("/tregister.html")
    public String teacherRegister(Model model) {
        return TEA_PATH + "tea-register";
    }

    @RequestMapping("/tlogin.html")
    public String teacherLogin(Model model) {
        log.info("\n-----teacherLogin-----\n");
        return TEA_PATH + "tea-login";
    }


    @RequestMapping("/tindex.html")
    public String tIndex(Model model, HttpSession session) {
        log.info("\n-----tIndex-view-----\n");
        if (session.getAttribute("user") != null) {
            return TEA_PATH + "tea-index";
        } else {
            return TEA_PATH + "tea-login";
        }
    }


    @RequestMapping("/tkecheng.html")
    public String tKecheng(Model model, HttpSession session) {
        log.info("\n-----tKecheng-view-----\n");
        if (session.getAttribute("user") != null) {
            return TEA_PATH + "tea-kecheng";
        } else {
            return TEA_PATH + "tea-login";
        }
    }

    @RequestMapping("/tkehome.html")
    public String tKehome(Model model, HttpSession session) {
        log.info("\n-----tKecheng-view-----\n");
//        if (session.getAttribute("user") != null) {
        return TEA_PATH + "tea-kehome";
//        } else {
//            return TEA_PATH + "tea-login";
//        }
    }

    @RequestMapping("/thome.html")
    public String tHome(Model model, HttpSession session) {
        log.info("\n-----tHome-view-----\n");
//        if (session.getAttribute("user") != null) {
        return TEA_PATH + "tea-home";
//        } else {
//            return TEA_PATH + "tea-login";
//        }
    }

    @RequestMapping("/tclassreview.html")
    public String tClassReview(Model model, HttpSession session) {
        log.info("\n-----tHome-view-----\n");
        if (Tools.userIsTeacher(session)) {
            return TEA_PATH + "tea-classreview";
        } else {
            return TEA_PATH + "tea-login";
        }
    }
}
